package com.wbao.dianniu.update;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.wbao.dianniu.R;
import com.wbao.dianniu.logical.GlobalContext;
import com.wbao.dianniu.ui.PerfectInfoActivity;

/**
 * 错误信息弹出框辅助类
 * <p>
 * Created by yejianjun on 2017/11/14.
 */

public class ErrorDialogHelper {

    private static ErrorDialogHelper instance;


    public static ErrorDialogHelper getInstance() {
        if (null == instance) {
            instance = new ErrorDialogHelper();
        }
        return instance;
    }

    /**
     * 显示完善资料弹出框
     */
    public Dialog showPerfectAuth(final Context context) {

        final Dialog dialog = new Dialog(context, R.style.custom_Dialog);
        Window win = dialog.getWindow();
        win.getDecorView().setPadding(3, 3, 3, 3);
        win.setGravity(Gravity.CENTER);
        View view = LayoutInflater.from(context).inflate(R.layout.custom_message_dialog, null);
        Button okBtn = (Button) view.findViewById(R.id.custom_msg_ok);
        Button cancelBtn = (Button) view.findViewById(R.id.custom_msg_cancel);
        TextView message = (TextView) view
                .findViewById(R.id.custom_msg_message);
        message.setText(context.getResources().getString(R.string.incomplete_preferct));
        dialog.setContentView(view);
        dialog.setCancelable(true);
        dialog.show();
        okBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (null != dialog && dialog.isShowing()) {
                    dialog.dismiss();
                }
                // 跳转到完善资料界面
                Intent intent = new Intent();
                intent.setClass(context, PerfectInfoActivity.class);
                context.startActivity(intent);
            }
        });
        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != dialog && dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        });

        return dialog;
    }

    /**
     * 显示积分不足弹出框
     */
    public Dialog showNoScore(final Context context) {
        final Dialog dialog = new Dialog(context, R.style.custom_Dialog);
        Window win = dialog.getWindow();
        win.getDecorView().setPadding(3, 3, 3, 3);
        win.setGravity(Gravity.CENTER);
        View view = LayoutInflater.from(context).inflate(R.layout.custom_message_dialog, null);
        Button okBtn = (Button) view.findViewById(R.id.custom_msg_ok);
        Button cancelBtn = (Button) view.findViewById(R.id.custom_msg_cancel);
        TextView message = (TextView) view.findViewById(R.id.custom_msg_message);
        message.setText(context.getResources().getString(R.string.score_deficiency));
        okBtn.setText(context.getResources().getString(R.string.to_invite));
        dialog.setContentView(view);
        dialog.setCancelable(true);
        dialog.show();
        okBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (null != dialog && dialog.isShowing()) {
                    dialog.dismiss();
                }
                ShareSDKManager shareSDKManager = ShareSDKManager.getInstance();
                // 邀请好友注册
                shareSDKManager.shareApp(context, GlobalContext.getAccountId());
            }
        });
        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != dialog && dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        });

        return dialog;
    }


}
